home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / DoubleBufferPanel.java < prev    next >
Text File  |  1998-09-15  |  983b  |  50 lines

  1. /*
  2.  * @(#)DoubleBufferPanel.java    1.1 98/07/18
  3.  *
  4.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  */
  7.  
  8. package actual;
  9.  
  10. import java.awt.*;
  11. import java.applet.*;
  12.  
  13. public class DoubleBufferPanel extends Panel {
  14.     
  15.   Image offscreen;
  16.  
  17.   /**
  18.    * null out the offscreen buffer as part of invalidation
  19.    */
  20.   public void invalidate() {
  21.       super.invalidate();
  22.       offscreen = null;
  23.   }
  24.  
  25.   /**
  26.    * override update to *not* erase the background before painting
  27.    */
  28.   public void update(Graphics g) {
  29.       paint(g);
  30.   }
  31.  
  32.   /**
  33.    * paint children into an offscreen buffer, then blast entire image
  34.    * at once.
  35.    */
  36.   public void paint(Graphics g) {
  37.       if(offscreen == null) {
  38.          offscreen = createImage(getSize().width, getSize().height);
  39.       }
  40.  
  41.       Graphics og = offscreen.getGraphics();
  42.       og.setClip(0,0,getSize().width, getSize().height);
  43.       super.paint(og);
  44.       g.drawImage(offscreen, 0, 0, null);
  45.       og.dispose();
  46.   }
  47.  
  48. }
  49.  
  50.